package com.conf;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

import org.apache.log4j.Logger;

/**
 * 
 * @author Administrator
 *
 */

public class CommonConfig {
	Logger logger = Logger.getLogger(CommonConfig.class);
	private static CommonConfig commonConfig = null;
	private static Properties properties = new Properties();

	/**
	 * 取配置文件实例
	 * @return
	 */
	public static CommonConfig getInstance() {
		return commonConfig;
	}
	
	/**
	 * 实例化
	 */
	static {
		commonConfig = new CommonConfig();
	}
	
	/**
	 * 加载配置文件
	 */
	private CommonConfig() {
		InputStream is = null;
		try {
			String sqlFileName = "CommonConfig.properties";
			is = getClass().getResourceAsStream(sqlFileName);
			properties.load(is);
		} catch (Exception e) {
			System.err.println("CommonConfig.properties加载CLASSPATH错误");
		}finally{
			try {
			if(is != null){ is.close();
			}} catch (IOException e) {
				e.printStackTrace();
				logger.error(e.getMessage());
			}
		}
	}

	/**
	 * 
	 * @param pSQLKeyName
	 * @return
	 * @throws Exception
	 */
	public static String getParamete(String keyName){
		String str = "";
		try{
			if (properties.containsKey(keyName))
				str =  (String) properties.get(keyName);
		}catch(Exception e){
			e.printStackTrace();
		}
		return str;
	}

	
}
